<template>
  <div style="width: 412px;margin: 0 auto;">
    <el-form :model="form" status-icon ref="form" label-width="100px" class="demo-ruleForm">
      <el-form-item label="商品id" prop="fruitId" style="width:380px">
        <el-input type="input" v-model="form.fruitId" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="商品名称" prop="fruitName" style="width:380px">
        <el-input type="input" v-model="form.fruitName" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="产地" prop="locality" style="width:380px">
        <el-input type="input" v-model="form.locality" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item label="价格" prop="price" style="width:380px">
        <el-input type="input" v-model="form.price" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submit()">提交</el-button>
      </el-form-item>

    </el-form>

  </div>
</template>

<script>
import axios from "../../utils/api";

export default {
  name: "AddRetailer",
  data() {
    return {
      form: {
        fruitId: '',
        fruitName: '',
        price: '',
        locality: '',
      },
    };
  },
  methods: {
    submit() {
      axios.post(axios.defaults.baseURL + "/addGoods", this.form).then(res => {
        if (res.data.data === 1) {
          alert("添加成功")
          location.reload()
        } else {
          alert("添加失败，商品id已存在，请重新添加")
        }
      }).catch(function (error) {
        alert(error);
        console.log(error);
      })
    },
  },

}
</script>

<style scoped>

</style>